//
// Created by Max on 2024/5/14.
//

#ifndef MIC_DETECT_SAVE_WAV_H
#define MIC_DETECT_SAVE_WAV_H

#include "SaveFile.h"
#include <tinyalsa/asoundlib.h>

#define ID_RIFF 0x46464952
#define ID_WAVE 0x45564157
#define ID_FMT 0x20746d66
#define ID_DATA 0x61746164

#define FORMAT_PCM 1

struct wav_header
{
    uint32_t riff_id;
    uint32_t riff_sz;
    uint32_t riff_fmt;
    uint32_t fmt_id;
    uint32_t fmt_sz;
    uint16_t audio_format;
    uint16_t num_channels;
    uint32_t sample_rate;
    uint32_t byte_rate;
    uint16_t block_align;
    uint16_t bits_per_sample;
    uint32_t data_id;
    uint32_t data_sz;
};

class SaveWav : public SaveFile
{
public:
    SaveWav(int channels, int rate, pcm_format format);
    ~SaveWav();
    int saveWav2File(int frames);
    int fSeekAfterWavHeader();
    int fSeekFileFileBegin();

private:
    struct wav_header mHeader;
};


#endif //MIC_DETECT_SAVE_WAV_H
